package com.gnerv.business.platform.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.gnerv.business.platform.entity.Dept;
import com.gnerv.business.platform.mapper.DeptMapper;
import com.gnerv.business.platform.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author gnerv
 * @since 2018-06-28
 */
@Service
public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements DeptService {

    @Autowired
    DeptMapper deptMapper;

    @Override
    public boolean updateByDeptId(Dept dept) {
        Integer i = deptMapper.updateByDeptId(dept);
        return i == 1 ? true : false;
    }

    @Override
    public boolean checkDeptName(Dept dept) {
        dept.setDeptId(null);
        dept.setId(null);
        Dept pDept = deptMapper.selectOne(dept);
        return !StringUtils.isEmpty(pDept) ? true : false;
    }

    @Override
    public boolean checkHasChlidDept(String pId) {
        Dept dept = new Dept();
        dept.setpId(pId);
        List<Dept> depts = deptMapper.selectList(new EntityWrapper<>(dept));
        return depts.size() > 0 ? true : false;
    }

}
